package com.briup.jz.web.controller;


import com.briup.jz.bean.BaseUser;

import com.briup.jz.service.IUserService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@Api(description = "用户管理接口")
public class UserController {
    @Autowired
    private IUserService userService;
    
    @ApiOperation(value = "级联角色查询")
    @GetMapping("findAllWithRole")
    private Message findAllWithRole(){
        return MessageUtil.success(userService.findAllWithRole());
    }
    @ApiOperation(value = "查询所有用户")
    @GetMapping("findAll")
    private Message  findAll(){
        return MessageUtil.success(userService.findAll());
    }

    @ApiOperation(value = "通过id查询用户")
    @GetMapping("findById")
    public Message findById(Long id) {

        return MessageUtil.success(userService.findById(id));
    }

    @ApiOperation(value = "通过id删除用户")
    @GetMapping("deleteById")
    public Message deleteById(Long id) {
        userService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
    @ApiOperation(value = "保存或更新用户")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(BaseUser user){
        userService.saveOrUpdate(user);
        return MessageUtil.success("保存成功");
    }
    @ApiOperation(value = "查询所有资讯")
    @GetMapping("query")
    public Message query(String realName, String status){
        List<BaseUser> list = userService.query(realName,status);
        return MessageUtil.success(list);
    }
 // 这里是假登录
 	@PostMapping("login")
 	public Message login(String username,String password) {
 		Map<String, String> map = new HashMap<>();
 		map.put("token", "admin");
 		return MessageUtil.success(map);
 	}
 	
 	// 这里是假获取用户信息
 	@GetMapping("info")
 	public Message info(String token) {
 		BaseUser user = new BaseUser();
 		user.setRealname("张三");
 		user.setUserFace("http://121.199.29.84:8888/group1/M00/00/16/rBD-SV_EpjyAa0qIAAA-lQCALyU911.jpg");
 		return MessageUtil.success(user);
 	}

}
